package com.ruoyi.web.controller.credit;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.credit.domain.ContractIncome;
import com.ruoyi.credit.service.IContractIncomeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 收入类合同Controller
 *
 * @author zhulei
 * @date 2022-03-10
 */
@Controller
@RequestMapping("/credit/contractIncome")
public class ContractIncomeController extends BaseController
{
    private String prefix = "credit/contractIncome";

    @Autowired
    private IContractIncomeService contractIncomeService;

    @RequiresPermissions("credit:contractIncome:view")
    @GetMapping()
    public String contractIncome()
    {
        return prefix + "/contractIncome";
    }

    @RequiresPermissions("credit:contractIncome:view")
    @GetMapping("/selectContract")
    public String selectContract()
    {
        return prefix + "/selectContract";
    }

    /**
     * 查询收入类合同列表
     */
    @RequiresPermissions("credit:contractIncome:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ContractIncome contractIncome)
    {
        startPage();
        List<ContractIncome> list = contractIncomeService.selectContractIncomeList(contractIncome);
        return getDataTable(list);
    }

    /**
     * 导出收入类合同列表
     */
    @RequiresPermissions("credit:contractIncome:export")
    @Log(title = "收入类合同", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ContractIncome contractIncome)
    {
        List<ContractIncome> list = contractIncomeService.selectContractIncomeList(contractIncome);
        ExcelUtil<ContractIncome> util = new ExcelUtil<ContractIncome>(ContractIncome.class);
        return util.exportExcel(list, "收入类合同数据");
    }

    /**
     * 新增收入类合同
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存收入类合同
     */
    @RequiresPermissions("credit:contractIncome:add")
    @Log(title = "收入类合同", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ContractIncome contractIncome)
    {
        return toAjax(contractIncomeService.insertContractIncome(contractIncome));
    }

    /**
     * 修改收入类合同
     */
    @RequiresPermissions("credit:contractIncome:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ContractIncome contractIncome = contractIncomeService.selectContractIncomeById(id);
        mmap.put("contractIncome", contractIncome);
        return prefix + "/edit";
    }

    /**
     * 修改保存收入类合同
     */
    @RequiresPermissions("credit:contractIncome:edit")
    @Log(title = "收入类合同", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ContractIncome contractIncome)
    {
        return toAjax(contractIncomeService.updateContractIncome(contractIncome));
    }

    /**
     * 删除收入类合同
     */
    @RequiresPermissions("credit:contractIncome:remove")
    @Log(title = "收入类合同", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(contractIncomeService.deleteContractIncomeByIds(ids));
    }
}
